package com.future.taskdemo.config;


import org.future.task.core.group.DefaultGroupImpl;
import org.future.task.core.handler.HandClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

@Component
public class TaskConfig implements ApplicationRunner {

    @Autowired
    private DefaultGroupImpl defaultGroup;

    @Override
    public void run(ApplicationArguments args) throws Exception {
//        Task t = new Task();
//        t.setQueueName("CC");
//        t.setThreadSize(10);
////        t.setUseCache(true);
////        t.setConnection(new RedisConnection());
//        t.setRunnableClass("com.future.taskdemo.task.TaskHandler");
//
//        Task tOne = new Task();
//        tOne.setQueueName("MM");
//        tOne.setQueueSize(10000);
//        tOne.setThreadSize(10);
//        tOne.setRunnableClass("com.future.taskdemo.task.TaskOne");
//
//        List<Task> tasks = new ArrayList<>();
//        tasks.add(t);
//        tasks.add(tOne);
//        SystemManager systemManager = new SystemManager(tasks, null, null, null, null, new DefaultConnection(1000));
//        systemManager.systemInit();
        Thr thr = new Thr();
        Thread thread = new Thread(thr);
        thread.start();
        Thread thread1 = new Thread(thr);
        thread1.start();
        Thread thread2 = new Thread(thr);
        thread2.start();

        defaultGroup.submit("HH");
    }

    class Thr implements Runnable {

        @Override
        public void run() {
            while (true) {
                try {
                    for (int i=0;i<800000000;i++) {
                        HandClient.cli("XX").sendCopyData(String.valueOf(i));
                    }
                    Thread.sleep(1);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
